package com.woniuxy.education.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.woniuxy.education.entity.Class;
import com.woniuxy.education.entity.*;
import com.woniuxy.education.mapper.StuAccountManageMapper;
import com.woniuxy.education.service.StuAccountManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StuAccountManageServiceImpl implements StuAccountManageService {
   @Autowired
   StuAccountManageMapper stuAccountManageMapper;
    @Override
    public void addUser(User user){
        stuAccountManageMapper.addUser(user);
    }
    @Override
    public User queryUserByU_id(Integer u_id){
      return   stuAccountManageMapper.queryUserByU_id(u_id);
    }
    @Override
    public void resetPassword(Integer u_id){
        stuAccountManageMapper.updateUserPassword(u_id);
    }
    @Override
    public void addStudent(Student student){
        stuAccountManageMapper.addStudent(student);
    }
    @Override
    public Student queryStudentByNumber(Integer number){
        return  stuAccountManageMapper.queryStudentByNumber(number);
    }
    @Override
    public User queryUserByAccount(String account){
        return  stuAccountManageMapper.queryUserByAccount(account);
    }
    @Override
    public PageResult<List<Student>> findStudent(int c_id, int page, int size){
            PageResult<List<Student>> result = new PageResult<>();
            Page<Object> startPage = PageHelper.startPage(page, size);
            List<Student> students = stuAccountManageMapper.findStudent(c_id);
            result.setCurrentPage(page);
            result.setSize(size);
            result.setTotal(startPage.getTotal());
            result.setTotalPage(startPage.getPages());
            result.setData(students);
            return result;
    };
    @Override
    public PageResult<List<Student>> searchStu(int c_id, int page, int size,String name){
        PageResult<List<Student>> result = new PageResult<>();
        Page<Object> startPage = PageHelper.startPage(page, size);
        List<Student> students = stuAccountManageMapper.searchStu(c_id,name);
        result.setCurrentPage(page);
        result.setSize(size);
        result.setTotal(startPage.getTotal());
        result.setTotalPage(startPage.getPages());
        result.setData(students);
        return result;
    }
    @Override
    public void addChangeStuClass(Change_StuClass change_StuClass){

        stuAccountManageMapper.addChangeStuClass(change_StuClass);

    }
    @Override
    public Class searchClassByC_id(Integer c_id){
        return  stuAccountManageMapper.searchClassByC_id(c_id);
    }
    @Override
    public List<Class> getAllClass(){
        return  stuAccountManageMapper.getAllClass();
    }
    @Override
    public List<Change_StuClass> queryStuChangeClass(Integer c_id,Integer state){
        return  stuAccountManageMapper.queryStuChangeClass(c_id,state);
    }
    @Override
    public Teacher queryTeacherByName(String name){
        return  stuAccountManageMapper.queryTeacherByName(name);
    }
    @Override
    public Change_StuClass queryStuChangClassByS_id(Integer s_id){
        return  stuAccountManageMapper.queryStuChangClassByS_id(s_id);
    }
    @Override
    public Change_StuClass queryStuChangClassById(Integer id){
        return stuAccountManageMapper.queryStuChangClassById(id);
    }
    @Override
    public boolean updateStuChangClassById(Integer state,Integer id,String end_date){
        return stuAccountManageMapper.updateStuChangClassById(state,id,end_date);
    }
    @Override
    public boolean updateStudentClass(Integer id, Integer c_id){
        return stuAccountManageMapper.updateStudentClass(id,c_id);
    }
    @Override
    public List<Class> getClassByG_id(Integer g_id){
        return stuAccountManageMapper.getClassByG_id(g_id);
    }
}
